package com.lansi.blegateway.service;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.lansi.blegateway.bean.Blegateway;
import com.lansi.blegateway.mapper.BlegatewayMapper;
import com.lansi.blegateway.service.ex.BlegatewayAlreadyExistException;

@Service
public class BlegatewayService implements IBlegatewayService{

	@Resource//注入持久层接口对象
	private BlegatewayMapper blegatewayMapper;
	
	public void getInsertBlegateway(Blegateway blegateway) {
		String deveui = blegateway.getDeveui();
		//查询该设备号是否存在
		Blegateway blegateway1 = blegatewayMapper.selectByDeveui(deveui);
		if(blegateway1 == null) {
			//进行添加操作
			blegatewayMapper.insertBlegateway(blegateway);
		}else {
			throw new BlegatewayAlreadyExistException("蓝牙网关设备号已存在！");
		}
	}

	public void delBlegatewayByDeveui(String deveui) {
		//根据设备号删除蓝牙网关信息
		blegatewayMapper.deleteBlegateway(deveui);
	}

	public void updateBlegatewayAllByDeveui(Blegateway blegateway) {
		//系统管理员进行修改操作(针对蓝牙网关所有信息)
		blegatewayMapper.updateBlegatewayAll(blegateway);
	}

	public void updateBlegatewayByDeveui(Blegateway blegateway) {
		//项目管理员对蓝牙网关的部分信息的修改
		blegatewayMapper.updateBlegateway(blegateway);
	}

	public Blegateway getByDeveui(String deveui) {
		//根据蓝牙网关的设备号进行查询
		Blegateway blegateway = blegatewayMapper.selectByDeveui(deveui);
		return blegateway;
	}

	public List<Blegateway> getBlegatewayBysn(String sn, Integer offset, Integer count) {
		//根据sn获取蓝牙网关的信息
		List<Blegateway> list = blegatewayMapper.selectBlegatewayBysn(sn, offset, count);
		return list;
	}

	public List<Blegateway> getBlegatewayAll(Integer offset, Integer count) {
		//获取所有蓝牙网关的信息
		List<Blegateway> list = blegatewayMapper.selectBlegatewayAll(offset, count);
		return list;
	}
	
	public Integer getSizeBlegatewayAll() {
		//获取所有蓝牙网关信息的条数
		Integer size = blegatewayMapper.selectSizeBlegatewayAll();
		return size;
	}

	public Integer getSizeBlegatewayBysn(String sn) {
		//根据sn获取蓝牙网关信息的条数
		Integer size = blegatewayMapper.selectSizeBlegatewayBysn(sn);
		return size;
	}


}
